import { CommonService } from "src/services/common.service"
import { diagram } from "./uielements"
export class Workspace {//工作区，保存用户的编辑故事的状态，一个工作区只能编辑一个故事
    constructor(parameters) {

    }
    public current: Story
    public currentobjectid: string//当前选择的对象id
    public showpropertyview: boolean
    public leftpanewidth: number = 80
    public openviewid: string[] = []//所有打开的编辑界面的id
}
//故事对象，包含了故事的全部信息
export class Story {

    public name: string = 'Unnamed Story'
    public memo: string = ''
    public createTime: Date = new Date()
    public author: string = 'lynx'
    public contact: string = 'lynxliu2002@163.com'//联系方式
    public keywords: string = ''
    public begin: Date = new Date(1974, 3, 7)//故事发生的起始时间
    public end: Date = new Date()
    public area: string = 'China'//故事发生的范围

    public Actors: Actor[] = []//角色列表
    public Events: Event[] = []//事件列表
    public Groups: Group[] = []//组列表，组的内部可以嵌套，用来包含角色和物品
    public Stuffs: Stuff[] = []//物品列表
    public Tasks: Task[] = []//任务列表，任务是故事里面的主要驱动力
    public Clues: Clue[] = []//线索，关联不同的元素的某种信息
    public Locations: Location[] = []//地点列表，包含故事发生的所有地点环境和场景

    public getEntityByID(id: string) {
        this.Actors.forEach(v => { if (v.Id === id) return v })
        this.Events.forEach(v => { if (v.Id === id) return v })
        this.Groups.forEach(v => { if (v.Id === id) return v })
        this.Stuffs.forEach(v => { if (v.Id === id) return v })
        this.Tasks.forEach(v => { if (v.Id === id) return v })
        this.Clues.forEach(v => { if (v.Id === id) return v })
        this.Locations.forEach(v => { if (v.Id === id) return v })
        return undefined
    }
    public Relations: Relation[] = []

    public Notes: Note[] = []
    public Expresses: Express[] = []//表达列表
    public Panoramas: Panorama[] = []//所有的全景图
}
export class Destiny {//某个对象的命运，有时间区间的
    constructor(target: StoryEntity, start: Date, end: Date, story: Story) {
        this.Target = target
        this.Start = start
        this.End = end
        story.Relations.forEach(r => {
            if (r.BeginTime < this.End || r.EndTime > this.Start) {
                if (r.SourceId == target.Id) {
                    let t = story.getEntityByID(r.TargetId)
                    if (t !== undefined) {
                        this.TargetDestinyInfos.push(new DestinyInfo(r, t))
                        this.Relations.push(r)
                    }


                }
                if (r.TargetId == target.Id) {
                    let t = story.getEntityByID(r.SourceId)
                    if (t !== undefined) {
                        this.SourceDestinyInfos.push(new DestinyInfo(r, t))
                        this.Relations.push(r)

                    }
                }
            }
        })
    }
    public Target: StoryEntity
    public Start: Date
    public End: Date
    public Relations: Relation[] = []
    //public SourceEntities: StoryEntity[] = []//和这个对象有关的所有对象
    //public TargetEntities: StoryEntity[] = []//和这个对象有关的所有对象

    public getEntity(info: DestinyInfo, story: Story): StoryEntity {
        return story.getEntityByID(info.EntityId)
    }
    public SourceDestinyInfos: DestinyInfo[] = []
    public TargetDestinyInfos: DestinyInfo[] = []
}


export class DestinyInfo {
    constructor(relation: Relation, entity: StoryEntity) {
        this.Start = relation.BeginTime
        this.End = relation.EndTime
        //this.RelationType = relationType
        //this.RelationInfo = relation.Grade + ':' + relation.Name
        this.EntityId = entity.Id
        if (entity instanceof Actor)
            this.EntityType = 'Actor'
        if (entity instanceof Group)
            this.EntityType = 'Group'
        if (entity instanceof Event)
            this.EntityType = 'Event'
        if (entity instanceof Clue)
            this.EntityType = 'Clue'
        if (entity instanceof Stuff)
            this.EntityType = 'Stuff'
        if (entity instanceof Task)
            this.EntityType = 'Task'
        if (entity instanceof Location)
            this.EntityType = 'Location'
        this.EntityInfo = entity.Name + '(' + relation.Name + ':' + relation.Description + ')'
    }
    public Start: Date
    public End: Date
    //public RelationInfo: string
    // public RelationType: string//source 或者target
    public EntityInfo: string
    public EntityType: string
    public EntityId: string

}

//全景图，里面包含了完整的事实和所有的信息和关联关系
export class Panorama {
    constructor() {

    }
    public Name: string = 'unnamed panorama'
    public Memo: string = ''
    public Diagram: diagram = new diagram()
    //该全景图包含的所有对象占比
    public getInfo(story: Story): number {
        return 0
    }
}
// export class ExpressObject {//场景表达的对象，只包括对象的简单信息
//     constructor(parameters) {

//     }
//     public TargetId: string
//     public Name: string
//     public Description: string
// }
export class Scene {
    constructor() {

    }
    //public IsEnable: boolean
    public SceneNumber: number = 0//每个场景都有编号
    //public MainMood: string//该场景的主要情绪
    //public Rhythm: number//
    //public StartSecond: number
    //public SpendSecond: number
    public Description: string = ''
    public ExpressObjectIds: string[] = []//参与场景的对象标识
    public Emotions: Emotion[] = []//情绪列表
    public Perspectivies: string[] = ['default']
}
// export class SceneExpress {
//     constructor() {

//     }
//     public SceneNumber: number
//     public Perspective: string//记录该次场景的表达特征，同样场景可以有不同角度的表达
//     public Remark: string //该表达的备注
// }
export class Episode {
    constructor() {

    }
    public Name: string = 'unnamed episode'
    public Description: string = ''
    public Spend: number = 3000//单位是秒
    //public Margin: number = 100//间隔前一个episode的时间
    //public SceneExpresses: SceneExpress[] = []
    public SceneNos: number[] = []//包含的场景列表，只记录场景的编号
}
export class Express {//一个表达，有自己的观众和特定的目标，也有版本，这个版本是独立于故事的
    constructor() {

    }
    public Name: string = 'default'
    public Memo: string = ''
    public Audiences: Audience[] = []//观众列表，每种表达都有自己的受众群
    public Length: number = 0//表达的长度，单位是秒
    public Version: string = "1.0"
    public Author: string
    public Episodes: Episode[] = []//包含的单元
    public Scenes: Scene[] = []//包含的所有描述的场景或者片段
    //返回该表达覆盖的所有事实信息
    public getInfoPercent(story: Story, objecttype: string): number {
        return 0
    }
}
export class Audience {//观众信息
    constructor() {

    }
    public AudienceType: string = 'default'
    public Memo: string = ''
    public priority: number = 1
}
export class Emotion {
    constructor() {

    }
    public Name: string
    public Memo: string
    //public Duration: number//情绪的持续时间
    public Grade: number//情绪的等级，强度
    //public Time: number//情绪发生时间，单位是秒
}
export class Resource {//实体对象的外部资源描述
    constructor() {

    }
    public ResourceId: string
    public Name: string
    public ResourceType: string
    public URL: string
    public Data: string
}

export class Note {
    constructor() {

    }
    public Memo: string = ''
    public NoteType: string = 'commert'
    public NoteId: string = CommonService.getid('Note')
}

//#region StoryEntity
export class StoryEntity {//所有的可以带有id的实体对象的基类
    constructor() {

    }
    public Name: string = 'unamed';
    public Description: string = '';
    public Id: string = CommonService.getid('SEn')
    public Keywords: string = ''
    public Grade: number = 0
    public Data: string = ''//这个是用来表示对象的外部数据，比如图片和视频，使用Base64编码
    public Resources: Resource[] = []
}
export class Actor extends StoryEntity {
    constructor() {

        super()

        this.Birthday = new Date(2009, 9, 11);
        this.Gender = '男';

    }
    public Birthday: Date;
    public Gender: string;


}

export class Stuff extends StoryEntity {
    constructor() {
        super()
        this.CreateTime = new Date(2009, 9, 11);
        this.Value = '';

    }

    public CreateTime: Date;
    public Value: string;

}
export class Location extends StoryEntity {

    public Posiion: string

    public ParentId: string

    public Longitude: number
    public Latitude: number
    public Altitude: number
}
export class Clue extends StoryEntity {

    public SignDescription: string

}
export class Task extends StoryEntity {
    constructor() {
        super()
        this.DeadLine = new Date(2009, 9, 11);
        this.Score = 0;

    }

    public DeadLine: Date;
    public Score: number;

}
export class Event extends StoryEntity {
    constructor() {
        super()
        this.DeadLine = new Date(2009, 9, 11);

    }

    public DeadLine: Date;

}
export class Group extends StoryEntity {
    constructor() {
        super()
        this.ParentId = undefined

        this.Member = []

    }
    public Id: string
    public ParentId: string
    public Name: string;
    public Description: string;
    public Member: [];
    public Grade: number;
    public Keywords: string
}

export class Relation extends StoryEntity {
    constructor() {
        super()
    }

    public SourceId: string;
    public TargetId: string
    public BeginTime: Date
    public EndTime: Date

}

//#endregion